<template>
  <div class="app-container">


    <el-table v-loading="loading" :data="ordersList">
      <el-table-column label="编号" align="center" prop="id"/>
      <el-table-column label="用户" align="center" prop="userId"/>
<!--      <el-table-column label="商品" align="center" prop="ordersGoods" width="180" show-overflow-tooltip/>-->
      <el-table-column label="门票" align="center" prop="ordersGoods">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="chakan(scope.row.ordersGoods,scope.row.ordersStatus)"
          >查看门票详情
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="ordersStatus"/>
      <el-table-column label="类型" align="center" prop="orderType"/>
      <el-table-column label="门票订单号" align="center" prop="orderId"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
          >修改
          </el-button>
          <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>


    <el-dialog title="订单门票详情" :visible.sync="open" width="80%" append-to-body>
      <el-table v-loading="loading" :data="cartList">
        <el-table-column label="名称" align="center" prop="toursimInfo.name" show-overflow-tooltip/>

        <el-table-column label="图片" align="center" prop="toursimInfo.photo" width="180">
          <template slot-scope="scope">
            <div v-if="!scope.row.toursimInfo.photo">暂无图像</div>
            <div v-else>
              <el-image
                  style="width: 50px; height: 50px"
                  :src="scope.row.toursimInfo.photo.split(',')[0]"
                  :preview-src-list="scope.row.toursimInfo.photo.split(',')">
              </el-image>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="描述" align="center" prop="toursimInfo.content" width="180" show-overflow-tooltip/>
        <el-table-column label="价格" align="center" prop="toursimInfo.price"/>
        <el-table-column label="数量" align="center" prop="toursimInfo.number">
        </el-table-column>
        <el-table-column  label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">

            <el-button

                size="mini"
                type="text"
                @click="pingjia(scope.row)"
            >评价
            </el-button>




          </template>
        </el-table-column>

      </el-table>
    </el-dialog>
    <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="queryParams.pageNum"
        :page-size="queryParams.pageSize"
        :page-sizes="[10,20,50]"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
    />

    <!-- 添加或修改门票订单管理对话框 -->
    <el-dialog :title="title" :visible.sync="open2" width="50%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-form-item label="用户" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户"/>
        </el-form-item>
        <el-form-item label="商品" prop="ordersGoods">
          <el-input v-model="form.ordersGoods" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="姓名" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入姓名"/>
        </el-form-item>
        <el-form-item label="手机" prop="userPhone">
          <el-input v-model="form.userPhone" placeholder="请输入手机"/>
        </el-form-item>
        <el-form-item label="状态">

          <el-select v-model="form.ordersStatus" placeholder="请选择类型">
            <el-option label="已购票" value="已购票"/>
            <el-option label="已退票" value="已退票"/>
          </el-select>




        </el-form-item>

        <el-form-item label="门票订单号" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入门票订单号"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listOrders, getOrders, delOrders, addOrders, updateOrders} from "@/api/project/orders";

export default {
  name: "Orders",
  data() {
    return {
      loading: true,
      // 总条数
      total: 0,
      // 门票订单管理表格数据
      ordersList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open2: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        ordersGoods: null,
        userName: null,
        userPhone: null,
        ordersStatus: null,
        orderType: null,
        orderId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    chakan(e,f){
      let data= JSON.parse(e)
      data.forEach(res=>{
        res.ordersStatus=f
      })
      this.cartList=data
      console.log(data)
      this.open=true
    },
    handlePageChange(currentPage) {
      this.queryParams.pageNum = currentPage
      this.getList()
    },
    handleSizeChange(pageSize) {
      this.queryParams.pageSize = pageSize
      this.getList()
    },
    /** 查询门票订单管理列表 */
    getList() {
      this.loading = true;
      listOrders(this.queryParams).then(response => {
        let list, start, end
        start = (this.queryParams.pageNum - 1) * this.queryParams.pageSize
        end = start + this.queryParams.pageSize
        list = response.data.filter((item, index) => {
          return index >= start && index < end
        })
        this.ordersList = list;
        this.total = response.data.length;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        ordersGoods: null,
        userName: null,
        userPhone: null,
        ordersStatus: "0",
        orderType: '门票',
        orderId: null
      };
      // this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加门票门票订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      getOrders(row).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改门票门票订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrders(this.form).then(response => {
              this.$message.success("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrders(this.form).then(response => {
              this.$message.success("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('是否确认删除？').then(function () {
        return delOrders(row);
      }).then(() => {
        this.getList();
        this.$message.success("删除成功");
      }).catch(() => {
      });
    },
  }
};
</script>
